package org.voidness.squaretilesframework;

import java.util.Vector;

import org.voidness.oje2d.GLImage;

/** A tile set to hold all tile images used in a map */
public class TileSet {
    /** The images's vector */
    private Vector<GLImage> images = null;

    /**
     * Default constructor
     */
    public TileSet() {
        images = new Vector<GLImage>();
    }

    /**
     * Adds a new image to the tileset
     * 
     * @param mNewImage The new image to add
     */
    public void addImage(GLImage mNewImage) {
        images.add(mNewImage);
    }

    /**
     * Returns the tile image at a given position
     * 
     * @param mIndex The index of the image to get
     * @return The GLImage at mIndex
     */
    public GLImage elementAt(int mIndex) {
        if (mIndex > -1 && mIndex < images.size())
            return (GLImage) images.elementAt(mIndex);
        return null;
    }

    /**
     * Returns the number of images in the tileset
     * 
     * @return The number of images
     */
    public int size() {
        return images.size();
    }

    /**
     * Attempts to find an image in the tileset based on it's filename
     * 
     * @param mFileName The filename to search
     * @return The image's index, if found, or -1 if the image is not in the
     *         tileset
     */
    public int find(String mFileName) {
        for (int i = 0; i < images.size(); i++) {
            GLImage image = (GLImage) images.elementAt(i);
            if (((GLImage) image).getFilename().equals(mFileName))
                return i;
            /*
             * if (image instanceof GLImage) { if
             * (((GLImage)image).getFilename().equals(mFileName)) return i; }
             * else if (image instanceof GLAnimatedImage) { if
             * (((GLAnimatedImage)image).getFilename().equals(mFileName)) return
             * i; }
             */
        }
        return -1;
    }
}